package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-07-16
 * Time: 11:40
 */
public class Login {
    String userName = "nihao";
    String userPassword = "123";
    public void login(String userName,String userPassword) throws UserNameException,UserPasswordException{
        if(!this.userName.equals(userName)) {
            throw new UserNameException("用户名错误");
        }
        if(!this.userPassword.equals(userPassword)) {
            throw new UserPasswordException("密码错误");
        }
        System.out.println("登录成功");
    }

    public static void main(String[] args) {
        try {
            Login login = new Login();
            login.login("ni","12");
        }catch (UserNameException e) {
            e.printStackTrace();
        }catch (UserPasswordException e) {
            e.printStackTrace();
        }
    }
}
